<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-11-11 09:36:52
 * @LastEditors: charles
 * @LastEditTime: 2021-11-11 10:22:50
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>refs</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.development.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.development.min.js"></script>
  <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
  <div id="app"></div>

  <script type="text/babel">

    
    function Box(props,ref){
      return (
        <div>
          <h3>我是图表</h3>  
          <p>{props.introduce}</p>
          <div ref={ref} style={
            {
              height:'100px',
              backgroundColor:"lightblue"
            }
          }></div>
        </div>
      )
    }
    // ref转发：ref获取到，然后转发到子组件box中
    Box = React.forwardRef(Box)
  
    class App extends React.Component {
      constructor(props){
        super(props);
        this.container = React.createRef();
      }
      componentDidMount(){
        console.log(this.container.current);
      }

      render(){
        return (
          <div className="container">
            <h2>refs转发</h2>
            <Box introduce={'政务办公数量折线图'} ref={this.container}/>
          </div>
        )
      }
    }
    ReactDOM.render(<App/>,document.getElementById('app'))
  </script>
</body>
</html>
